/**
 * 验证类
 * */
import validator from "validator";

export class ValidateTool {
  // validator验证器
  static validator = validator;

  // 验证是否是电话(支持手机号与座机)
  static isMobile(mobile: string): boolean {
    return /^((0\d{2,3}-\d{7,8})|(1[3-9]\d{9}))$/.test(mobile);
  }

  // 验证统一信用代码
  static isCert(cert: string): boolean {
    return /^(\d|[a-z]|[A-Z]){15,20}$/g.test(cert);
  }

  // 验证是否是手机号
  static isPhone(phone: string): boolean {
    return /^1[3-9][0-9]{9}$/.test(phone);
  }

  // 校验是否为空
  static isEmpty(value: any): boolean {
    return value === undefined || value === null;
  }

  // 校验"是"
  static isYes(value: any): boolean {
    return value === 1;
  }
}